package com.oyjd.beauty.business.body.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oyjd.beauty.bean.po.Body;
import com.oyjd.beauty.bean.vo.BodyVO;
import com.oyjd.beauty.business.body.dao.BodyDao;
import com.oyjd.beauty.business.body.service.BodyService;
import com.oyjd.beauty.fw.action.Page;

/**
 * 
 * 体型信息业务接口实现
 * 
 * @author <b>欧建东<br/>
 *         Email:oyjd@163.com</b>
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class BodyServiceImpl implements BodyService {
	private BodyDao dao;

	@Autowired
	public void setDao(BodyDao dao) {
		this.dao = dao;
	}

	/**
	 * 获取体型信息列表数据
	 * 
	 * @param page
	 *            页面对象
	 * @return
	 */
	public Page<BodyVO> getList(Page<BodyVO> page) {
		return dao.getList(page);
	}

	/**
	 * 根据ID获取体型信息对象信息
	 * 
	 * @param id
	 *            ID
	 * @return
	 */
	public BodyVO getBodyVO(String bodyId) {
		return dao.getBodyVO(bodyId);
	}

	/**
	 * 增加体型信息
	 * 
	 * @param name
	 *            名称
	 * @param note
	 *            描述
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void add(String name, String note, String user) {
		Date date = new Date();
		Body body = new Body();
		body.setName(name);
		body.setNote(note);
		body.setCreator(user);
		body.setCreateTime(date);
		body.setLastEditor(user);
		body.setLastUpdateTime(date);
		body.setStatus(0);
		dao.create(body);
	}

	/**
	 * 修改体型信息
	 * 
	 * @param bodyId
	 *            体型ID
	 * @param name
	 *            名称
	 * @param note
	 *            描述
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void edit(String bodyId, String name, String note, String user) {
		Date date = new Date();
		Body body = (Body) dao.queryById(Body.class, bodyId);
		body.setBodyId(bodyId);
		body.setName(name);
		body.setNote(note);
		body.setLastEditor(user);
		body.setLastUpdateTime(date);
		dao.update(body);
	}

	/**
	 * 删除体型信息
	 * 
	 * @param ids
	 *            多个ID
	 * @param user
	 *            当前用户
	 * @return
	 */
	@Transactional(readOnly = false)
	public void remove(String[] ids, String user) {
		dao.remove(ids, user);
	}

}
